package com.easyctba.core.controller;

import java.util.List;

import com.easyctba.core.domain.bo.FrontProjectBo;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.easyctba.common.idempotent.annotation.RepeatSubmit;
import com.easyctba.common.log.annotation.Log;
import com.easyctba.common.web.core.BaseController;
import com.easyctba.common.mybatis.core.page.PageQuery;
import com.easyctba.common.core.domain.R;
import com.easyctba.common.core.validate.AddGroup;
import com.easyctba.common.core.validate.EditGroup;
import com.easyctba.common.log.enums.BusinessType;
import com.easyctba.common.excel.utils.ExcelUtil;
import com.easyctba.core.domain.vo.CtbaEntropyVo;
import com.easyctba.core.domain.bo.CtbaEntropyBo;
import com.easyctba.core.service.ICtbaEntropyService;
import com.easyctba.common.mybatis.core.page.TableDataInfo;

/**
 * 信息熵分析
 * 前端访问路由地址为:/core/entropy
 *
 * @author LionLi
 * @date 2024-02-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/entropy")
public class CtbaEntropyController extends BaseController {

    private final ICtbaEntropyService ctbaEntropyService;

    /**
     * 查询信息熵分析列表
     */
    @SaCheckPermission("core:entropy:list")
    @GetMapping("/list")
    public TableDataInfo<CtbaEntropyVo> list(CtbaEntropyBo bo, PageQuery pageQuery) {
        return ctbaEntropyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出信息熵分析列表
     */
    @SaCheckPermission("core:entropy:export")
    @Log(title = "信息熵分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CtbaEntropyBo bo, HttpServletResponse response) {
        List<CtbaEntropyVo> list = ctbaEntropyService.queryList(bo);
        ExcelUtil.exportExcel(list, "信息熵分析", CtbaEntropyVo.class, response);
    }

    /**
     * 获取信息熵分析详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("core:entropy:query")
    @GetMapping("/{id}")
    public R<CtbaEntropyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(ctbaEntropyService.queryById(id));
    }

    /**
     * 新增信息熵分析
     */
    @SaCheckPermission("core:entropy:add")
    @Log(title = "信息熵分析", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CtbaEntropyBo bo) {
        return toAjax(ctbaEntropyService.insertByBo(bo));
    }

    /**
     * 修改信息熵分析
     */
    @SaCheckPermission("core:entropy:edit")
    @Log(title = "信息熵分析", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CtbaEntropyBo bo) {
        return toAjax(ctbaEntropyService.updateByBo(bo));
    }

    /**
     * 删除信息熵分析
     *
     * @param ids 主键串
     */
    @SaCheckPermission("core:entropy:remove")
    @Log(title = "信息熵分析", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(ctbaEntropyService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 分析方法api
     * @param bo 条件参数
     */
    @PostMapping("/v1/analyze")
    public R<Void> analyze(@RequestBody CtbaEntropyBo bo) {
        return ctbaEntropyService.analyze(bo);
    }

    /**
     * 根据项目id获取信息熵分析信息
     * @param id 项目id
     * @return VO对象
     */
    @GetMapping("/v1/{id}")
    public R<CtbaEntropyVo> getInfoByUserAndProject(@PathVariable Long id) {
        return ctbaEntropyService.getInfoByUserAndProject(id);
    }

    /**
     * 完成分析
     * @param id 信息熵分析id
     */
    @PutMapping("/v1/finish/{id}")
    public R<Void> finish(@PathVariable Long id) {
        return ctbaEntropyService.finish(id);
    }

    /**
     * 上一步
     * @param id 信息熵分析全局唯一id
     */
    @PutMapping("/v1/pre/{id}")
    public R<Void> pre(@PathVariable Long id){
        return ctbaEntropyService.pre(id);
    }
}
